<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css">
    <script src="../res/layui/layui.js"></script>
    <script src="../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async: false
        });
        function getQueryString(name){
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;}
        var id = getQueryString("id");
    </script>
</head>
<body>
<form class="layui-form" action="" id="AtsDataDic">
    <input type="hidden" name="did" id="did" value="0"/>
    <div class="layui-form-item">
        <label class="layui-form-label">字典编码：</label>
        <div class="layui-input-block">
            <input type="text" name="dcode" id="dcode" required
                   lay-verify="required" placeholder="请输入角色名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典名称：</label>
        <div class="layui-input-block">
            <input type="text" name="dname" id="dname" required
                   lay-verify="required" placeholder="请输入角色名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典类型：</label>
        <div class="layui-input-block">
            <input type="text" name="dtype" id="dtype" required
                   lay-verify="required" placeholder="请输入角色名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div style="margin-left: 110px;margin-top: 10px;  ">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>

<script>
    //Demo    $(function(){})
    var form = null ;
    layui.use('form', function(){
        var rolesId = "";
        form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            $("input[name='roles']:checked").each(function(index,item){
                rolesId+=$(this).val()+",";
            });
            $("#ids").val(rolesId);
            //layer.msg(JSON.stringify(data.field));
            var formData = new FormData(document.getElementById("AtsDataDic"));
            var url = "../AtsDataDic/diczj";
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            //parent.location.reload();
                        });
                    }else{
                        layer.msg(obj.msg);
                    }
                },
                error:function(e){
                    layer.msg("操作错误!");
                }
            });
            return false;
        });
        fromfz();
    });
    function fromfz() {
        var id = getQueryString("id");
        if(id!=null){
            var url = "../AtsDataDic/findId";
            var data = {id:id};
            $.get(url, data, function (obj) {
                $("#did").val(obj.did);
                $("#dcode").val(obj.dcode);
                $("#dname").val(obj.dname);
                $("#dtype").val(obj.dtype);
            }, "json");
        }
    }
</script>
</body>
</html>